<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<c:set var="queryList" value="${pageContext.request.contextPath}/permission/list" />
<style>
.select2-container--default .select2-selection--single {
	border-color: #d8dde6;
	border-radius: 0;
	height: 32px;
}
</style>
<div class="iframe-cot pull-right"  id="smIframe" style="background:#FFFFFF;">
    
    <div class="right-form">
        <form id="_query_form" action="" class="form-inline" onsubmit="return false;">
             <div class="tb_search">
             <div class="pull-left">             
                  <span class="search-more">更多条件<i class="fa fa-angle-down ml5"></i></span>
                    <div class="form-group">
                        <label for="permissionName">权限名称：</label>
						<input type="text"  name="permissionName" value="${fn:escapeXml(permissionName) }" />
                   </div>       
                   <div class="form-group">
                        <label for="menuName">所属菜单：</label>
						<input type="text"  name="menuName" value="${menuNamee }" />
                   </div>
                   <div class="form-group">
                    	<label for="appId">所属应用：</label>
							<select name="appId" class="js-example-basic-single form-control-select" >
							<option value="" ></option>
							    <c:forEach items="${appList}" var="app">
									<option value="${app.code}" <c:if test="${app.code eq appId }"  >selected</c:if> >${app.name }</option>
								</c:forEach>  
							</select>
                   </div>
				  
             </div>
             </div>             
         </form>
     </div>
     
     <div class="line-e6e"></div>
     <div class="form-top">
     	<div class="pull-left">
     	<shiro:hasPermission name="common-service-permission:add">
     	 	<button class="btn btn-default" onclick="goAdd('${ctx}/permission/add','新增权限')"><i class="fa fa-plus mr5"></i>新增</button>
     	</shiro:hasPermission>
     	<shiro:hasPermission name="common-service-permission:edit">
     		<button class="btn btn-default" onclick="goUpdate('${ctx}/permission/edit','修改权限信息')"><i class="fa fa-pencil mr5"></i>编辑</button>
        </shiro:hasPermission>
        <shiro:hasPermission name="common-service-permission:delete"> 
            <button class="btn btn-default" onclick="deleteById()"><i class="fa fa-times mr5"></i>删除</button>
     	</shiro:hasPermission>
     	</div>
     	<div class="pull-right">
     	<shiro:hasPermission name="common-service-permission:query">
     		<button type="button" class="btn btn-orange" onclick="changePage('${queryList }/table','#_query_form','1','${pageBean.pageSize }',0,true)"><i class="fa fa-search mr5"></i>查询</button>
            <button type="button" class="btn btn-blue" onclick="clearForm('#_query_form')"><i class="fa fa-trash-o mr5"></i>清空</button>
     	</shiro:hasPermission>
     	</div>
     </div>
     
     <div id="table-papination">
     	
     </div>           
   </div>

          <!--main end--> 
 <script src="${ctx}/static/js/search-more.js"></script>  <!--更多查询条件--> 
 <script src="${ctx}/static/js/select2-4.0.3/dist/js/select2.js"></script>     
 <script type="text/javascript">


 currentPageNo = parseInt('${pageBean.currentPage}');
 currentPageSize = parseInt('${pageBean.pageSize }');
 totalPageCount = parseInt('${pageBean.totalPage}');
 queryUrl = '${ctx}/permission/list';
 
 $(document).ready(function(){
	  $(".js-example-basic-single").select2({
		  placeholder:"请选择",
		  'language':{
				'noResults':function(){
					return "<p>无符合条件数据</p>";
				}
			},
			escapeMarkup: function (markup) {
		        return markup;
		    }
	  });
	  //加载表格内容
	  loadConent('${queryList }/table','',true);
 });

 function deleteById(){
	// alert(id);
		//检查该权限是否已授权给其它角色
	var ids = getListTableCheckboxValue();
	if( ids == ''){
		 warnTip('请选择一条记录');
		 return;
	 }	
	var tips = '删除权限，拥有该权限的角色会失去该权限, \n是否继续执行操作';
	_delete(ids,tips);
	/*  $.post("/permission/get/role/count/"+id,{},function(result){
		 	var isUsed = true;//默认已被授权给其它角色
		 	var tips = '删除权限，拥有该权限的角色会失去该权限 \n是否继续执行操作';
	  		if(result.code=="success" && result.count == 0){
	  			isUsed = false;
	  			tips = '删除权限，是否继续执行操作';
	  		}
	  		_delete(id,tips,isUsed);
	  	},"json"); */
		
	}
 function _delete(ids,tips){
	 layer.confirm(tips, {
	  	    btn: ['确定', '取消']
	  	    ,yes: function(index){
	  	    	$.post("/permission/delete/"+ids,{},function(result){
	  	  		if(result.code=="success"){
	  	  			successTip();
	  	  		 	//setInterval("window.location.href='/standardmethod/index'",2000);
	  	  			//刷新列表
	  	  			changePage('${queryList }/table','#permissionQueryForm','1','${pageBean.pageSize }',0,true);
	  	  		}else{
	  	  			errorTip();
	  	  		}
	  	  	},"json");
	  	    }
	  	});
 }
 
 </script>